//
//  SetImgView.m
//  YiXiProject
//
//  Created by iMac on 2019/7/24.
//  Copyright © 2019 iMac. All rights reserved.
//  10     49     1:13-1:40   1:46   2:18   2:42   3:32

#import "SetImgView.h"

@implementation SetImgView 

-(UIView *)topBgView
{
    if(!_topBgView)
    {
        _topBgView = [[UIView alloc] init];
        _topBgView.backgroundColor = WhiteColor;
    }
    return _topBgView;
}

-(UILabel *)settingLabel
{
    if(!_settingLabel)
    {
        _settingLabel = [[UILabel alloc] init];
        _settingLabel.text = @"Settings";
        _settingLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:35];
    }
    return _settingLabel;
}

-(UIImageView *)leftImg
{
    if(!_leftImg)
    {
        _leftImg = [[UIImageView alloc] init];
        _leftImg.backgroundColor = WhiteColor;
        _leftImg.layer.cornerRadius = 10;
        _leftImg.layer.masksToBounds = YES;
        _leftImg.userInteractionEnabled = YES;
    }
    return _leftImg;
}

-(UIImageView *)rightOneImg
{
    if(!_rightOneImg)
    {
        _rightOneImg = [[UIImageView alloc] init];
        _rightOneImg.backgroundColor = WhiteColor;
        _rightOneImg.layer.cornerRadius = 10;
        _rightOneImg.layer.masksToBounds = YES;
        _rightOneImg.userInteractionEnabled = YES;
    }
    return _rightOneImg;
}

-(UIImageView *)rightTwoImg
{
    if(!_rightTwoImg)
    {
        _rightTwoImg = [[UIImageView alloc] init];
        _rightTwoImg.backgroundColor = WhiteColor;
        _rightTwoImg.layer.cornerRadius = 10;
        _rightTwoImg.layer.masksToBounds = YES;
        _rightTwoImg.userInteractionEnabled = YES;
    }
    return _rightTwoImg;
}

-(UIButton *)leftImgBtn
{
    if(!_leftImgBtn)
    {
        _leftImgBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _leftImgBtn.backgroundColor = ClearColor;
        _leftImgBtn.tag = 100;
        [_leftImgBtn addTarget:self action:@selector(chooseImg:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftImgBtn;
}

-(UIButton *)rightOneImgBtn
{
    if(!_rightOneImgBtn)
    {
        _rightOneImgBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _rightOneImgBtn.backgroundColor = ClearColor;
        _rightOneImgBtn.tag = 101;
        [_rightOneImgBtn addTarget:self action:@selector(chooseImg:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightOneImgBtn;
}

-(UIButton *)rightTwoImgBtn
{
    if(!_rightTwoImgBtn)
    {
        _rightTwoImgBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _rightTwoImgBtn.backgroundColor = ClearColor;
        _rightTwoImgBtn.tag = 102;
        [_rightTwoImgBtn addTarget:self action:@selector(chooseImg:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightTwoImgBtn;
}

-(UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        _nameLabel = [[UILabel alloc] init]; //WithFrame:CGRectMake(15, SCREEN_WIDTH-50, SCREEN_WIDTH-30, 50)];
        _nameLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
    }
    return _nameLabel;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.topBgView];
        [self.topBgView addSubview:self.settingLabel];
        
        [self addSubview:self.leftImg];
        [self addSubview:self.rightOneImg];
        [self addSubview:self.rightTwoImg];
        
        [self.leftImg addSubview:self.leftImgBtn];
        [self.rightOneImg addSubview:self.rightOneImgBtn];
        [self.rightTwoImg addSubview:self.rightTwoImgBtn];
        
        [self addSubview:self.nameLabel];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _topBgView.sd_layout.leftSpaceToView(self, 0).topSpaceToView(self, 0).rightSpaceToView(self, 0).heightIs(60);
    _settingLabel.sd_layout.leftSpaceToView(_topBgView, 15).topSpaceToView(_topBgView, 10).rightSpaceToView(_topBgView, 0).heightIs(40);
    
    _leftImg.sd_layout.leftSpaceToView(self, 10).topSpaceToView(_topBgView, 10).widthIs(SCREEN_WIDTH/2-15).bottomSpaceToView(self, 60);
    _rightOneImg.sd_layout.leftSpaceToView(_leftImg, 10).topSpaceToView(_topBgView, 10).rightSpaceToView(self, 10).heightIs((self.bounds.size.height-110)/2-15);
    _rightTwoImg.sd_layout.leftSpaceToView(_leftImg, 10).topSpaceToView(_rightOneImg, 10).rightSpaceToView(self, 10).bottomSpaceToView(self, 60);
    
    _leftImgBtn.sd_layout.leftSpaceToView(_leftImg, 0).topSpaceToView(_leftImg, 0).rightSpaceToView(_leftImg, 0).bottomSpaceToView(_leftImg, 0);
    _rightOneImgBtn.sd_layout.leftSpaceToView(_rightOneImg, 0).topSpaceToView(_rightOneImg, 0).rightSpaceToView(_rightOneImg, 0).bottomSpaceToView(_rightOneImg, 0);
    _rightTwoImgBtn.sd_layout.leftSpaceToView(_rightTwoImg, 0).topSpaceToView(_rightTwoImg, 0).rightSpaceToView(_rightTwoImg, 0).bottomSpaceToView(_rightTwoImg, 0);
    
    _nameLabel.sd_layout.leftSpaceToView(self, 15).topSpaceToView(_leftImg, 10).rightSpaceToView(self, 15).bottomSpaceToView(self, 0);
}


-(void)chooseImg:(UIButton *)btn
{
    if([_delegate respondsToSelector:@selector(clickImgButtonTag:)])
    {
        [_delegate clickImgButtonTag:btn.tag];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
